#pragma once

#include <QDir>
#include <QFileSystemWatcher>
#include "ISimpleChannel.h"

struct DirectorySettings
{
    QString path;  
    QString filemask;
    QString extension; 
    bool createIfDontExist; 
    bool isNamingArbitrary; 
    bool autodel;
    bool active;
};

class Directory : public ISimpleChannel
{
    Q_OBJECT

public:
    Directory(const DirectorySettings& settings);

public:
    virtual bool       Open();
    virtual bool       IsOpened();
    virtual void       Reset();
    virtual void       Close();

    virtual unsigned   DataAvailable();
    virtual QString    LastError();
    virtual QString    Info();

    virtual QByteArray Receive(unsigned size);
    virtual unsigned   Send(const QByteArray& data);

private:
    bool MakeActive();

private slots:
    void OnNewFile();

private:
    DirectorySettings   _settings;
    QDir                _dir;
    QFileSystemWatcher  _watcher;
    QString             _latestAffected;
    QString             _lastError;
    unsigned            _fileIndex;    
};